﻿using MediatR;
using ProduceBasicData.Api.Application.Command.ProductionManage.Technology;
using ProduceBasicData.Domain.WarehouseManage;
using ProduceBasicData.ErrorCode;
using ProduceBasicData.Infrastructure.Interface;

namespace ProduceBasicData.Api.Application.Handler.ProductionManage.Technology
{
    /// <summary>
    /// 仓库库位下拉框
    /// </summary>
    public class GetWarehouseZoneCommandHandler : IRequestHandler<GetWarehouseZoneCommand, ApiResult<List<WarehouseZone>>>
    {
        private readonly IBaseRespository<WarehouseZone> _warehousezone;

        public GetWarehouseZoneCommandHandler(IBaseRespository<WarehouseZone> warehousezone)
        {
            _warehousezone = warehousezone;
        }

        public Task<ApiResult<List<WarehouseZone>>> Handle(GetWarehouseZoneCommand request, CancellationToken cancellationToken)
        {
            var result = new ApiResult<List<WarehouseZone>>()
            {
                Code = ApiEnum.Success,
                Msg = "仓库库区查询成功"
            };
            var listhousezone = _warehousezone.GetAll().Where(o => o.WarehouseId == request.WarehouseId);

            result.Data = listhousezone.ToList();

            return Task.FromResult(result);
        }
    }
}
